home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Freeware / Griffith 0.9.8 / griffith-0.9.8-win32.exe / {app} / lib / plugins / movie / PluginMovieFilmAffinity.py < prev    next >
Text File  |  2008-11-17  |  6KB  |  157 lines

  1. # -*- coding: iso-8859-15 -*-
  2.  
  3. __revision__ = '$Id: PluginMovieFilmAffinity.py 389 2006-07-29 18:43:35Z piotrek $'
  4.  
  5. # Copyright (c) 2006 Pedro D. Sßnchez
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
  20.  
  21. # You may use and distribute this software under the terms of the
  22. # GNU General Public License, version 2 or later
  23.  
  24. import gutils
  25. import movie
  26. import string
  27.  
  28. plugin_name        = 'FilmAffinity'
  29. plugin_description    = 'Base de Datos de Peliculas'
  30. plugin_url        = 'www.filmaffinity.com'
  31. plugin_language        = _('Spanish')
  32. plugin_author        = 'Pedro D. Sßnchez'
  33. plugin_author_email    = '<pedrodav@gmail.com>'
  34. plugin_version        = '0.2'
  35.  
  36. class Plugin(movie.Movie):
  37.     def __init__(self, id):
  38.         self.encode='iso-8859-15'
  39.         self.movie_id = id
  40.         self.url = "http://www.filmaffinity.com/es/film%s.html" % str(self.movie_id)
  41.  
  42.     def get_image(self):
  43.         tmp = string.find(self.page, '<img src="http://www.filmaffinity.com/imgs/movies/')
  44.         if tmp == -1:
  45.             self.image_url = ''
  46.         else:
  47.             self.image_url = gutils.trim(self.page[tmp-1:], 'src="', '"')
  48.  
  49.     def get_o_title(self):
  50.         self.o_title = gutils.trim(self.page, '<b>TITULO ORIGINAL</b></td>', '</b></td>')
  51.         self.o_title = gutils.after(self.o_title, '<b>')
  52.  
  53.     def get_title(self):
  54.         self.title = gutils.trim(self.page, '<img src="http://www.filmaffinity.com/images/movie.gif" border="0"> ', '</span>')
  55.  
  56.     def get_director(self):
  57.         self.director = gutils.trim(self.page,'<b>DIRECTOR</b></td>', '</td>')
  58.  
  59.     def get_plot(self):
  60.         self.plot = gutils.trim(self.page, '<b>G╔NERO Y CR═TICA</b>', '<br />')
  61.         if self.plot == '':
  62.             self.plot = gutils.trim(self.page, '<b>GÉNERO Y CRÍTICA</b>', '<br />')
  63.         self.plot = gutils.after(self.plot, '<td valign="top">')
  64.         self.plot = gutils.after(self.plot, '/')
  65.         self.plot = string.replace(self.plot, ' SINOPSIS: ', '')
  66.         self.plot = string.replace(self.plot, ' SINOPSIS:', '')
  67.         self.plot = string.replace(self.plot, 'SINOPSIS: ', '')
  68.         self.plot = string.replace(self.plot, 'SINOPSIS:', '')
  69.         self.plot = string.replace(self.plot, ' (FILMAFFINITY)', '')
  70.         self.plot = string.replace(self.plot, '(FILMAFFINITY)', '')
  71.  
  72.     def get_year(self):
  73.         self.year = gutils.trim(self.page, '<b>A╤O</b></td>', '</td>')
  74.         self.year = gutils.after(self.year, '<td >')
  75.  
  76.     def get_runtime(self):
  77.         self.runtime = gutils.trim(self.page, '<b>DURACI╙N</b></td>', ' min.</td>')
  78.         if self.runtime == '':
  79.             self.runtime = gutils.trim(self.page, '<b>DURACIÓN</b></td>', ' min.</td>')
  80.         self.runtime = gutils.after(self.runtime[-10:], '<td>')
  81.  
  82.     def get_genre(self):
  83.         self.genre = gutils.trim(self.page, '<b>G╔NERO Y CR═TICA</b>', '<br />')
  84.         if self.genre == '':
  85.             self.genre = gutils.trim(self.page, '<b>GÉNERO Y CRÍTICA</b>', '<br />')
  86.         self.genre = gutils.trim(self.genre, '<td valign="top">', '/')
  87.         self.genre = string.replace(self.genre, '.', " /")
  88.  
  89.     def get_cast(self):
  90.         self.cast = ''
  91.         self.cast = gutils.trim(self.page, '<b>REPARTO</b></td>', '</td>')
  92.         self.cast = string.replace(self.cast, '</a>,', '\n')
  93.         self.cast = string.strip(gutils.strip_tags(self.cast))
  94.         self.cast = string.replace(self.cast, '  ', '')
  95.  
  96.     def get_classification(self):
  97.         self.classification = ''
  98.  
  99.     def get_studio(self):
  100.         self.studio = gutils.trim(self.page, '<b>PRODUCTORA</b></td>', '</td>')
  101.         self.studio = gutils.after(self.studio, '<td  >')
  102.  
  103.     def get_o_site(self):
  104.         self.o_site = gutils.trim(self.page, '<b>WEB OFICIAL</b></td>', '</a>')
  105.         self.o_site = gutils.after(self.o_site, '">')
  106.  
  107.     def get_site(self):
  108.         self.site = "http://www.filmaffinity.com/es/film%s.html" % str(self.movie_id)
  109.  
  110.     def get_trailer(self):
  111.         self.trailer = ''
  112.  
  113.     def get_country(self):
  114.         self.country = gutils.trim(self.page, '<b>PA═S</b></td>', '</td>')
  115.         self.country = gutils.trim(self.country, 'alt="', '"')
  116.  
  117.     def get_rating(self):
  118.         self.rating = gutils.trim(self.page, '<tr><td align="center" style="color:#990000; font-size:22px; font-weight: bold;">', '</td></tr>')
  119.         if self.rating:
  120.             self.rating = str(float(gutils.clean(string.replace(self.rating, ',', '.'))))
  121.  
  122. class SearchPlugin(movie.SearchMovie):
  123.  
  124.     def __init__(self):
  125.         self.original_url_search    = 'http://www.filmaffinity.com/es/search.php?stype=title&stext='
  126.         self.translated_url_search    = 'http://www.filmaffinity.com/es/search.php?stype=title&stext='
  127.         self.encode = 'iso-8859-15'
  128.  
  129.     def search(self,parent_window):
  130.         self.open_search(parent_window)
  131.         auxPage = self.page
  132.         self.sub_search()
  133.         if self.page <> '':
  134.             return self.page
  135.         auxPage = gutils.trim(auxPage, '<b>TU CR═TICA</b></div>', '</a>')
  136.         self.page = gutils.trim(auxPage, 'movie_id=', '">')
  137.         return self.page
  138.  
  139.     def sub_search(self):
  140.         self.page = gutils.trim(self.page, 'Resultados por tφtulo</span>', '<br>')
  141.         #self.page = gutils.after(self.page, '</td></tr><tr><td><b>')
  142.         #self.page = self.page.decode('iso-8859-15')
  143.  
  144.     def get_searches(self):
  145.         if len(self.page) < 20:    # immidietly redirection to movie page
  146.             self.number_results = 1
  147.             self.ids.append(self.page)
  148.             self.titles.append(self.url)
  149.         else:            # multiple matches
  150.             elements = string.split(self.page, '</a></b>')
  151.  
  152.             if (elements[0]<>''):
  153.                 for element in elements[:-1]:
  154.                     self.ids.append(gutils.trim(element, '<b><a href="/es/film','.html'))
  155.                     title = gutils.after(element, '<b><a href="/es/film')
  156.                     self.titles.append(gutils.strip_tags(gutils.convert_entities(gutils.after(title, '>'))))
  157.